using System;

namespace BSDS.Core.Intialization
{
    public class BsdsEngine : IDisposable
    {
        public BsdsServicesLocator Services { get; private set; }

        #region IDisposable Members

        public void Dispose()
        {
            if (Services != null)
            {
                if (Services.TempFolderManager != null)
                {
                    Services.TempFolderManager.Dispose();
                }

                if (Services.MutexHolder != null)
                {
                    Services.MutexHolder.Dispose();
                }
            }
        }

        #endregion

        public void Initialize()
        {
            Initialize(new DefaultInitializationOptionsProvider());
        }

        public void Initialize(IBsdsIntializationOptionsProvider optionsProvider)
        {
            Services = new BsdsModule().Build();
            
            Services.JobRepository.Initialize();
            Services.MutexHolder.Initialize(optionsProvider);
            Services.TempFolderManager.Intialize();
        }
    }
}